<%= header %>
<!--
IE9 (and older) and phantomjs do not fire 'loadend' for XHRs, no autoxhr beacon was being sent
-->
<script src="00-xhrs.js" type="text/javascript"></script>
<%= boomerangScript %>
<script>
window.xoUrl = "//<%= secondaryServer %>:" + window.location.port + "/blackhole";

BOOMR_test.init({
	testAfterOnBeacon: BOOMR.plugins.AutoXHR ? 13 : 1,
	instrument_xhr: true,
	autorun: true,
	afterFirstBeacon:
		function() {
			if (!BOOMR.plugins.AutoXHR) {
				return;
			}

			var xhrNum = 0;
			function sendBeacon() {
				setTimeout(function() {
					var xhr;
					if (xhrNum === 0) {
						xhr = new XMLHttpRequest();
						xhr.open("GET", "support/script200.js?rnd=" + Math.random());  // 200, async
						xhr.send(null);
					}
					else if (xhrNum === 1) {
						xhr = new XMLHttpRequest();
						xhr.open("GET", "support/script200.js?rnd=" + Math.random(), false);  // 200, sync
						xhr.send(null);
					}
					else if (xhrNum === 2) {
						xhr = new XMLHttpRequest();
						xhr.open("GET", "/404?rnd=" + Math.random());  // 404, async
						xhr.send(null);
					}
					else if (xhrNum === 3) {
						xhr = new XMLHttpRequest();
						xhr.open("GET", "/404?rnd=" + Math.random(), false);  // 404, sync
						xhr.send(null);
					}
					else if (xhrNum === 4) {
						xhr = new XMLHttpRequest();
						xhr.open("GET", window.xoUrl + "?rnd=" + Math.random());  // X-O error (no ACAO header)
						xhr.send(null);
					}
					else if (xhrNum === 5) {
						xhr = new XMLHttpRequest();
						xhr.open("GET", "/support/script200.js?rnd=" + Math.random());  // 200, async, abort
						xhr.send(null);
						xhr.abort();
					}
					else if (xhrNum === 6) {
						xhr = new XMLHttpRequest();
						xhr.open("GET", "/delay?delay=1000&file=support/script200.js&rnd=" + Math.random());  // 200, async, timeout
						xhr.timeout = 250;
						xhr.send(null);
					}
					else if (xhrNum === 7) {
						xhr = new XMLHttpRequest();
						xhr.open("POST", "/blackhole?rnd=" + Math.random());  // 204, POST
						xhr.send(null);
					}
					else if (xhrNum === 8) {
						xhr = new XMLHttpRequest();
						xhr.open("POST", "/delay?delay=1000&file=/blackhole&rnd=" + Math.random());  // 204, POST, timeout
						xhr.timeout = 250;
						xhr.send(null);
					}
					else if (xhrNum === 9) {
						xhr = new XMLHttpRequest();
						xhr.open("POST", "/drop?rnd=" + Math.random());  // server dropped connection
						xhr.send(null);
					}
					else if (xhrNum === 10) {
						xhr = new XMLHttpRequest();
						xhr.open("GET", "/500?rnd=" + Math.random());  // 500, async
						xhr.send(null);
					}
					else if (xhrNum === 11) {
						xhr = new XMLHttpRequest();
						xhr.open("GET", "/chunked?chunkSize=1000&chunkCount=10&chunkDelay=500&rnd=" + Math.random());  //200, chunked, async
						xhr.send(null);
					}
					xhrNum++;
				}, 100);
			}

			// send a new XHR on each beacon
			BOOMR.subscribe("beacon", sendBeacon);

			// start the first beacon
			sendBeacon();
		}
});
</script>
<%= footer %>
